/**
 * Created by doubleyong on 2020/8/25.
 */
const myexpress = require('express');
const favicon = require('serve-favicon');
const logger = require('morgan');
const bodyParser = require('body-parser');
const cookieParser = require("cookie-parser");
const session = require('express-session');
const pageRouter = require('./router/pageRouter')
const userRouter = require('./router/userRouter')
const productRouter = require('./router/productRouter')
const ejs = require('ejs')
const app = myexpress();
//配置

// app.use(logger('dev'));

app.set('views',__dirname+'/src')
app.engine('html',ejs.__express)
app.set('view engine','html')

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.use(cookieParser());
app.use(session({
    secret: '1234',
    name: 'testapp',   //这里的name值得是cookie的name，默认   cookie的name是：connect.sid
    cookie: {maxAge: 800000 },  //设置maxAge是80000ms，即80s后session和相应的            cookie失效过期
    rolling:true,   //是否按照原设定的maxAge值重设session同步到cookie中，要保证session有操作的时候必须设置这个属性为true
    resave:true,     //是指每次请求都重新设置session cookie，假设你的cookie是10分钟过期，每次请求都会再设置10分钟
    saveUninitialized:true,//是指无论有没有session cookie，每次请求都设置个session cookie ，默认给个标示为 connect.sid
}));
app.use(pageRouter)
app.use(userRouter)
app.use(productRouter)
app.use(myexpress.static(__dirname+"/src"));
app.use(favicon(__dirname+'/src/images/cai.jpg'));

app.listen(8888);
console.log("服务启动")